package com.kingint.web.admin.serve.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kingint.common.unitedresult.K;
import com.kingint.mbg.group.Insert;
import com.kingint.mbg.ser.entity.SerCycleCleanPlan;
import com.kingint.mbg.ser.entity.SerRoomClean;
import com.kingint.web.admin.serve.service.SerRoomCleanService;
import com.kingint.web.portal.serve.service.RoomCleanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @描述：客房清洁单控制类
 * @作者: wxh
 * @日期: 2020-12-30
 */
@RestController
@RequestMapping("/serRoomClean")
@Api(value = "SerRoomCleanController", description = "客房清洁单")
@CrossOrigin
public class SerRoomCleanController {

    @Autowired
    public SerRoomCleanService roomCleanService;


    @ApiOperation(value = "添加客房清洁单")
    @PostMapping("/create")
    public Object create(@Validated(Insert.class) @RequestBody SerRoomClean serRoomClean) {
        String instanceid = roomCleanService.addcleanorder(serRoomClean);
        if (StringUtils.isEmpty(instanceid)) return K.error();
        return K.ok().data(instanceid);
    }

    @ApiOperation(value = "根据工单号分页获取")
    @GetMapping("/list")
    public Object getList(SerRoomClean serRoomClean,
                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize){
        Page<SerRoomClean> page = new Page<>(pageNum, pageSize);
        IPage<SerRoomClean> info = roomCleanService.getpage(page,serRoomClean);
//        IPage<SerCycleCleanPlan> info=serCycleCleanPlanService.page(page,null);
        return K.ok().data(info);
    }

    @ApiOperation(value = "完成节点")
    @GetMapping("/complete")
    public Object acceptorder(@RequestParam("id") Integer serWorkOderId, @RequestParam(required = false) Integer checkstate) {
        Boolean b = roomCleanService.acceptorder(serWorkOderId, checkstate);
        return b ? K.ok() : K.error();
    }

    @ApiOperation(value = "根据编号查询客房清洁单信息")
    @DeleteMapping("delete/{id}")
    public Object delete(@PathVariable("id") Integer id) {
        boolean serRoomClean = roomCleanService.delete(id);
        return K.ok().data(serRoomClean);
    }

    @ApiOperation(value = "清洁人员接单")
    @GetMapping("/roomCleanReceiver")
    public Object roomCleanReceiver(@RequestParam("id") Integer serWorkOderId) {
        Boolean b = roomCleanService.acceptorder(serWorkOderId, null);
        return b ? K.ok() : K.error();
    }
}